#!/bin/bash
source /etc/profile.d/jdk17.sh

JAVA_HOME=$JAVA_HOME
ROOT_HOME=/opt
SRC_HOME=${ROOT_HOME}/program
PRJ_HOME=${SRC_HOME}/datadir
DATADIR_PATH=${ROOT_HOME}/datadir
DATADIR_LOG_PATH=${DATADIR_PATH}/logs
DATADIR_ACCON_NAME=Beijing
DATADIR_LISTEN_PORT=28280
DATADIR_DATASOURCE_URL="jdbc:mysql://8.130.72.63:18080/datadir?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8"
DATADIR_DATASOURCE_USERNAME="datadir"
DATADIR_DATASOURCE_PASSWORD="Datadir!1@2#3"
DATADIR_VAULT_URL="http://127.0.0.1:8200"
DATADIR_VAULT_TOKEN="hvs.oEeDsKPmCQNcpicLWIfEc4Sy"
DATADIR_REDIS_HOST="8.130.72.63"
DATADIR_REDIS_PORT=18084
DATADIR_REDIS_IDX=12
DATADIR_REDIS_PASSWD="Taiji#2024data"
DATADIR_MINIO_ACCESSKEY="ROOTNAME"
DATADIR_MINIO_SECRETKEY="CHANGEME123"
DATADIR_MINIO_ENDPOINT="http://1.95.78.201:30002"
ps -ef |grep datadir.jar |awk '{print $2}'|xargs kill -9
cd ${PRJ_HOME}/
git pull
mvn clean package -DskipTests
/bin/rm -f /opt/datadir/logs/*
/bin/rm -rf /opt/datadir/lib/*
/bin/rm -rf /opt/datadir/upload/*
ln -sf ${PRJ_HOME}/target/*.jar /opt/datadir/lib/datadir.jar
#java -jar /opt/datadir/lib/datadir.jar >/tmp/datadir.log 2>&1
JAVA_OPTS="$JAVA_OPTS -Djava.awt.headless=true"
JAVA_OPTS="$JAVA_OPTS -DDATADIR_PATH=${DATADIR_PATH}"
JAVA_OPTS="$JAVA_OPTS -DDATADIR_LOG_PATH=${DATADIR_LOG_PATH}"
JAVA_OPTS="$JAVA_OPTS -DDATADIR_ACCON_NAME=${DATADIR_ACCON_NAME}"
JAVA_OPTS="$JAVA_OPTS -DDATADIR_LISTEN_PORT=${DATADIR_LISTEN_PORT}"
JAVA_OPTS="$JAVA_OPTS -DDATADIR_DATASOURCE_URL=${DATADIR_DATASOURCE_URL}"
JAVA_OPTS="$JAVA_OPTS -DDATADIR_DATASOURCE_USERNAME=${DATADIR_DATASOURCE_USERNAME}"
JAVA_OPTS="$JAVA_OPTS -DDATADIR_DATASOURCE_PASSWORD=${DATADIR_DATASOURCE_PASSWORD}"
JAVA_OPTS="$JAVA_OPTS -DDATADIR_VAULT_URL=${DATADIR_VAULT_URL}"
JAVA_OPTS="$JAVA_OPTS -DDATADIR_VAULT_TOKEN=${DATADIR_VAULT_TOKEN}"
JAVA_OPTS="$JAVA_OPTS -DDATADIR_REDIS_HOST=${DATADIR_REDIS_HOST}"
JAVA_OPTS="$JAVA_OPTS -DDATADIR_REDIS_PORT=${DATADIR_REDIS_PORT}"
JAVA_OPTS="$JAVA_OPTS -DDATADIR_REDIS_IDX=${DATADIR_REDIS_IDX}"
JAVA_OPTS="$JAVA_OPTS -DDATADIR_REDIS_PASSWD=${DATADIR_REDIS_PASSWD}"
JAVA_OPTS="$JAVA_OPTS -DDATADIR_MINIO_ACCESSKEY=${DATADIR_MINIO_ACCESSKEY}"
JAVA_OPTS="$JAVA_OPTS -DDATADIR_MINIO_SECRETKEY=${DATADIR_MINIO_SECRETKEY}"
JAVA_OPTS="$JAVA_OPTS -DDATADIR_MINIO_ENDPOINT=${DATADIR_MINIO_ENDPOINT}"
CLASSPATH=.:$JAVA_HOME/lib/jrt-fs.jar
export JAVA_HOME CLASSPATH JAVA_OPTS
java ${JAVA_OPTS} -jar /opt/datadir/lib/datadir.jar